<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

		<title>个人资料</title>

		<link href="../AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
		<link href="../AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">

		<link href="../css/personal.css" rel="stylesheet" type="text/css">
		<link href="../css/infstyle.css" rel="stylesheet" type="text/css">
		<script src="../AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
		<script src="../AmazeUI-2.4.2/assets/js/amazeui.js"></script>
		<script src="../js/login.js"></script>			
	</head>

	<body>
		<!--头 -->
		<header>
			<article>
				<div class="mt-logo">
					<!--顶部导航条 -->
					<div class="am-container header">
						<ul class="message-l">
							<div class="topMessage">
								<div class="menu-hd">
									<a href="login.html" target="_top" class="h" id="login">亲，请登录</a>
									<a href="register.html" target="_top">免费注册</a>
								</div>
							</div>
						</ul>
						<ul class="message-r">
							<div class="topMessage home">
								<div class="menu-hd"><a href="home2.html" target="_top" class="h">商城首页</a></div>
							</div>
							<div class="topMessage my-shangcheng">
								<div class="menu-hd MyShangcheng"><a href="index.html" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a></div>
							</div>
							<div class="topMessage mini-cart">
								<div class="menu-hd"><a id="mc-menu-hd" href="shopcart.html" target="_top"><i class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum" class="h">0</strong></a></div>
							</div>
							<div class="topMessage favorite">
						</ul>
						</div>

						<!--悬浮搜索框-->

						<div class="nav white">
							<div class="logoBig">
								<li><img src="../images/logobig.png" /></li>
							</div>

							<div class="search-bar pr">
								<a name="index_none_header_sysc" href="search.html"></a>
								<form action="search.html">
									<input id="searchInput" name="index_none_header_sysc" type="text" placeholder="搜索" autocomplete="off">
									<input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="submit">
								</form>
							</div>
						</div>

						<div class="clear"></div>
					</div>
				</div>
			</article>
		</header>
            <div class="nav-table">
					   <div class="long-title"><span class="all-goods">全部分类</span></div>
					   <div class="nav-cont">
							<ul>
								<li class="index"><a href="home2.html">首页</a></li>
							</ul>
						    <div class="nav-extra">
						    	<i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
						    	<i class="am-icon-angle-right" style="padding-left: 10px;"></i>
						    </div>
						</div>
			</div>
			<b class="line"></b>
		<div class="center">
			<div class="col-main">
				<div class="main-wrap">

					<div class="user-info">
						<!--标题 -->
						<div class="am-cf am-padding">
							<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">个人资料</strong> / <small>Personal&nbsp;information</small></div>
						</div>
						<hr/>

						<!--头像 -->
						<div class="user-infoPic">

							
								<!-- <input type="file" class="inputPic" allowexts="gif,jpeg,jpg,png,bmp" accept="image/*"> -->
								<!-- <img type="file" id="user_img" οnchange="upload(this)" class="am-circle am-img-thumbnail" src="../images/getAvatar.do.jpg" alt="修改头像" /> -->
								<!-- <input id="load" type="file" οnchange="upload(this)" multiple/>
        						<div id="huixian"></div> -->


							<form
								action="../../save/saveImg" id="touxiangForm"
								enctype="multipart/form-data" method="post" onsubmit="return false;">
								<input type="submit" value="修改" onclick="touxiang()"/>
								<img id="picture"  src="../../static/admin/images/1.jpg" width="106" alt="" type="file" onchange="showPic(this)">
								<input type="file" name="upload" id='file' 
									onchange="showPic(this)" /> 
									 
							</form>


						

							<p class="am-form-help">头像</p>

							<div class="info-m">
								<div><b>用户名：<i id="username">阿三</i></b></div>
								<div class="vip">
                                      <span></span><a href="#">会员专享</a>
								</div>
							</div>
						</div>

						<!--个人信息 -->
						<div class="info-main">
							<form class="am-form am-form-horizontal" id="userForm">
								<input type="hidden" id="user_id" value="" name="user_id">
								<div class="am-form-group">
									<label for="user-name2" class="am-form-label">账号</label>
									<div class="am-form-content">
										<input type="text" readonly="readonly" id="user_loginname"  name="user_loginname" placeholder="nickname"  autocomplete="off">
                                         
									</div>
								</div>

								<div class="am-form-group">
									<label for="user-name" class="am-form-label">昵称</label>
									<div class="am-form-content">
										<input type="text" id="user_fullname" name="user_fullname" placeholder="昵称"  autocomplete="off">
                                          <small>昵称长度不能超过10个汉字</small>
									</div>
								</div>

								<div class="am-form-group">
									<label class="am-form-label">性别</label>
									<div class="am-form-content sex" >
										<input type="text" id="user_sex" name="user_sex" placeholder="性别"  autocomplete="off">
									</div>
								</div>

								<div class="am-form-group">
									<label for="user-birth" class="am-form-label">生日</label>
									<div class="am-form-content birth" >
										<input type="text" id="user_birthday" name="user_birthday" placeholder="yyyy-MM-dd"  autocomplete="off">
									</div>
							
								</div>
								<div class="am-form-group">
									<label for="user-phone" class="am-form-label">电话</label>
									<div class="am-form-content">
										<input id="user_phone" placeholder="telephonenumber" type="tel" name="user_phone"  autocomplete="off">

									</div>
								</div>
								<div class="am-form-group">
									<label for="user-email" class="am-form-label">电子邮件</label>
									<div class="am-form-content">
										<input id="user_email" name="user_email" placeholder="Email" type="email"  autocomplete="off">

									</div>
								</div>
								<!-- <div class="am-form-group address">
									<label for="user-address" class="am-form-label">收货地址</label>
									<div class="am-form-content address" name>
										<a href="address.html">
											<p class="new-mu_l2cw">
												<span class="province">湖北</span>省
												<span class="city">武汉</span>市
												<span class="dist">洪山</span>区
												<span class="street">雄楚大道666号(中南财经政法大学)</span>
												<span class="am-icon-angle-right"></span>
											</p>
										</a>

									</div>
								</div> -->
								<div class="am-form-group safety">
									<label for="user-safety" class="am-form-label">账号安全</label>
									<div class="am-form-content safety">
										<a href="safety.html">

											<span class="am-icon-angle-right"></span>

										</a>

									</div>
								</div>
								<div class="info-btn">
									<!-- <div class="am-btn am-btn-danger" type="submit" >保存修改</div> -->
									<input type="submit" id="baocun" name="" value="保存"
								class="am-btn am-btn-primary am-btn-sm">
								</div>

							</form>
						</div>

					</div>

				</div>
				<!--底部-->
				<div class="footer">
					<div class="footer-hd">
						<p>
								<b>|</b>
								<a href="home2.html">商城首页</a>
								<b>|</b>
								<a href="# ">支付宝</a>
								<b>|</b>
								<a href="# ">物流</a>
							</p>
						</div>
						<div class="footer-bd ">
							<p>
								<a href="# ">合作伙伴</a>
								<a href="# ">联系我们</a>
								<a href="# ">网站地图</a>
							</p>
					</div>
				</div>
			</div>

			<aside class="menu">
				<ul>
					<li class="person active">
						<a href="index.html"><i class="am-icon-user"></i>个人中心</a>
					</li>
					<li class="person">
						<p><i class="am-icon-newspaper-o"></i>个人资料</p>
						<ul>
							<li> <a href="information.html">个人信息</a></li>
							<li> <a href="safety.html">安全设置</a></li>
							<li> <a href="address.html">地址管理</a></li>
							<li> <a href="cardlist.html">快捷支付</a></li>
						</ul>
					</li>
					<li class="person">
						<p><i class="am-icon-balance-scale"></i>我的交易</p>
						<ul>
							<li><a href="order.html">订单管理</a></li>
							<li> <a href="change.html">退款售后</a></li>
							<li> <a href="comment.html">评价商品</a></li>
						</ul>
					</li>
					<li class="person">
						<p><i class="am-icon-dollar"></i>我的资产</p>
						<ul>
							<li> <a href="points.html">我的积分</a></li>
							<li> <a href="coupon.html">优惠券 </a></li>
							<li> <a href="bonus.html">红包</a></li>
							<li> <a href="walletlist.html">账户余额</a></li>
							<li> <a href="bill.html">账单明细</a></li>
						</ul>
					</li>

					<li class="person">
						<p><i class="am-icon-tags"></i>我的收藏</p>
						<ul>
							<li> <a href="collection.html">收藏</a></li>
							<li> <a href="foot.html">足迹</a></li>														
						</ul>
					</li>

					<li class="person">
						<p><i class="am-icon-qq"></i>在线客服</p>
						<ul>
							<li> <a href="consultation.html">商品咨询</a></li>
							<li> <a href="suggest.html">意见反馈</a></li>							
							
							<li> <a href="news.html">我的消息</a></li>
						</ul>
					</li>
				</ul>

			</aside>
		</div>
<script type="text/javascript">
$(function(){ // jquery的ready函数，页面加载完毕之后自动执行
	$.post("../../userAll",{user_id:localStorage.getItem("user_id")},function(res){
		$("#user_id").val(res[0].user_id);
		$("#user_loginname").val(res[0].user_loginname);
		$("#user_fullname").val(res[0].user_fullname);
		$("#user_sex").val(res[0].user_sex);
		$("#user_birthday").val(res[0].user_birthday);
		$("#user_phone").val(res[0].user_phone);
		$("#user_email").val(res[0].user_email);
		document.getElementById("picture").src="../../static/admin/images/"+res[0].user_img;
		document.getElementById("username").value=res[0].user_fullname;
	},"json");
})





$(function(){
	$("#userForm").submit(function(){

	
	$.post("../../userUpdate",$("#userForm").serialize(),function(res){
		console.log(res);
		if(res.code=="0"){
			alert("修改成功");
			$.post("../../login",{
				user_loginname:localStorage.getItem("user_loginname"),
				user_pwd:localStorage.getItem("user_pwd")
			},function(res){
				if (res.code=="0") {
					localStorage.setItem("user_id",res.data.user_id);
					localStorage.setItem("user_fullname",res.data.user_fullname);
					
				}
			},"json");
		}else{
			alert("修改失败");
		}
	},"json");
	return false;
	});
});

function touxiang(){
	var url=$("#file").val();
	var img = url.substring(url.lastIndexOf("\\")+1); 
	$.post("../../updateImg",{
			user_img:img,
			user_id:localStorage.getItem("user_id")
		},function(res){
		if (res.code=="0") {
			//window.location.reload();
			alert("修改成功");
		} else {
			alert("不能修改");
		}
	},"json");
}

</script>

     <!-- <input id="load" type="file" οnchange="upload(this)" multiple/>
        <div id="huixian"></div> -->
        <script type="text/javascript">
        function upload(obj){ 
            var f = obj.files;
            console.log(f);
            var str = "";
            for(var i=0;i<f.length;i++){
                var reader = new FileReader();
                reader.readAsDataURL(f[i]);
                reader.onload = function(e){
                    str+='<img src="'+e.target.result+'"/>';
                   document.getElementById("huixian").innerHTML = str;
                }
            }
        }
        </script>
<script type="text/javascript">
$("#touxiangForm").ajaxForm(function (data) {
    console.log(data);
    console.log("str:" + JSON.stringify(data));
}
);
    //图片回显+图片格式+文件类型
    function showPic(obj) {
        var newPreview = document.getElementById('picture');
        if (obj) {
            //ie浏览器兼容 
            if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                obj.select();
                newPreview.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);";
                var path = document.selection.createRange().text;
                var flag = judgeImgSuffix(path);
                if (flag) {
                    newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.selection.createRange().text;
                } else {
                    alert("要求图片格式为png,jpg,jpeg,bmp");
                }
                
                return;
            }
            //firefox浏览器兼容 
            else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                if (obj.files) {
                    newPreview.src = window.URL.createObjectURL(obj.files.item(0));
                    return;
                }
                newPreview.src = obj.value;
                return;
            }
            newPreview.src = obj.value;
            return;
        }
    }

    function judgeImgSuffix(path) {
        var index = path.lastIndexOf('.');
        var suffix = "";
        if (index > 0) {
            suffix = path.substring(index + 1);
        }
        if ("png" == suffix || "jpg" == suffix || "jpeg" == suffix
                || "bmp" == suffix || "PNG" == suffix || "JPG" == suffix
                || "JPEG" == suffix || "BMP" == suffix) {
            return true;
        } else {
            //alert("请上传正确到的图片格式");
            return false;
        }

    }
</script>
	</body>

</html>